<?php
/**
 * alltosun.com 客户端设备号列表 index.php
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 雷健雄 (leijx@alltosun.com) $
 * $Date: 2015-2-26 上午11:05:21 $
 * $Id: index.php 211119 2015-02-28 07:12:27Z leijx $
 */

class Action
{
    private $per_page = 30;

    public function __call($action = '', $params = array())
    {
        $search_filter = array();
        $filter  = array();
        $order   = ' ORDER BY `id` DESC ';
        $page_no = Request::getParam('page_no', 1);
        // $status  = Request::getParam('status', 1);

        $search_filter = Request::getParam('search_filter', array());
        $default_value  = array(
                'nick_name'   => '',
                'id'          => '',
                'add_time >=' => '',
                'add_time <=' => ''
        );
        // $search_filter  = set_search_filter_default_value($search_filter, $default_value);
        $filter = array('1'=>1);
        // $filter['status'] = $status;

        /*
        $user_ids = _model('device')->getFields('user_id', array(1=>1));
        $user_ids = array_unique($user_ids);
        $user_list = _model('user')->getList($user_ids);

        // 得到得到昵称和系统消息id的一维数组
        $user_nick_names = array_to_option($user_list, 'nick_name');
        //系统消息昵称搜索
        if (isset($search_filter['nick_name']) && $search_filter['nick_name']) {
            foreach ($user_nick_names as $k => $nick_name) {
                if (strstr($nick_name, AnFilter::filter_string(trim($search_filter['nick_name'])))) {
                    $filter['user_id'][] = $k;
                }
            }
        }

        // 系统消息id搜索
        if (isset($search_filter['user_id']) && $search_filter['user_id']) {
            $filter_user_ids = explode(',', trim($search_filter['user_id'], ','));
            if ($filter['user_id']) {
                $filter['user_id'] = array_merge($filter_user_ids, $filter['user_id']);
            } else {
                $filter['user_id'] = $filter_user_ids;
            }
        }
        */

        if (isset($search_filter['receiver_type']) && $search_filter['receiver_type']) {
            $filter['receiver_type'] = $search_filter['receiver_type'];
        }

        if (isset($search_filter['start_add_time']) && $search_filter['start_add_time']) {
            $filter['add_time >= '] = $search_filter['start_add_time'].' 00:00:00';
        }
        if (isset($search_filter['end_add_time']) && $search_filter['end_add_time']) {
            $filter['add_time <= '] = $search_filter['end_add_time'].' 23:59:59';
        }

        $total = _model('device')->getTotal($filter);
        if ($total) {
            $list = get_data_list('device', $filter, $order, $page_no, $this->per_page);
            $device_list = $list;
            Response::assign('device_list', $device_list);
        }

        Response::assign('filter', $filter);
        Response::assign('search_filter', $search_filter);
        // Response::assign('status', $status);
        Response::display('admin/device_list.html');
    }
}
?>